﻿using System;
using System.Collections.Generic;
using System.Text;

using Common.IO.FileIO;
using BL.ServerBL;

namespace UI.SystemServerConsole
{
    public class SystemServer 
    {
        ServerChannel SystemServerChannel;
        string IniFileName = "SystemServerConsole.ini";
        bool IsServerOpened;
        bool IsAutoStarted = true;


        public SystemServer()
        {
            this.InitDBConfig();
        }

        private void InitDBConfig()
        {
            IniFileIO inifile = new IniFileIO(this.IniFileName);
            string serverip = inifile.IniReadValue("DataBase", "DBServerIP");
            string dbver = inifile.IniReadValue("DataBase", "DBVer");
            DBConfigControl.SetDBConfig(serverip, dbver);
       }

   
        
        public void ChannelControl(bool bl)
        {
            SystemServerChannel.ServerChannelControl(bl);
            if (bl)
            {
                IsServerOpened = true;
            }
            else
            {
                IsServerOpened = false;
            }
        }



        public bool InitServer()
        {
            IniFileIO programini = new IniFileIO(IniFileName, false);
            bool isautostart = (programini.IniReadValue("Server", "AutoStart") == "1");
            string port = programini.IniReadValue("Server", "Port");
            SystemServerChannel = new ServerChannel(port);
            if (!SystemServerChannel.RegisterServerChannel())
            {
                return false;
            }
            return true;
        }

        public void QuitServer()
        {
            SystemServerChannel.UnRegisterServerChannel();
        }

    


    }
}
